<template>
  <div class="components-container">
    <div>
      <div>
        <div class="layui-inline">
          <!-- <label >冰柜区域选择</label> -->
          <div class="layui-inline">
            <el-radio-group size="large" v-model="icaSelectIndex" @change="getIceData">
              <el-radio-button v-for="(item,index) in iceArea" :key="item.ICAID" :label="index" class="radio">
                <span style="display:block;min-width:100px;">{{item.ICANAME}}</span>
              </el-radio-button>
            </el-radio-group>
          </div>
          <div class="layui-inline">
            <el-button type="primary" class="refresh" size="large" @click="btnOnload">刷新</el-button>
          </div>
        </div>
      </div>
      <div class="tableContainer" style="position:relative;margin-left:auto;">
        <div v-for="y in iceAreaItem.ICAYCOUNT" :style="{width:iceAreaItem.ICAXCOUNT*left+'px',height:top}" style="clear:left;">
          <div v-for="x in iceAreaItem.ICAXCOUNT" class="iceplace iceplacedefault"></div>
        </div>
        <div class="freezerBtn">
          <ul class="tableIceArea" style="position: absolute; left: 0; top: 0;">
            <li v-for="(item, index) in iceAreaInfo" :style="{left: (left*(item.ICEXP-1)) + 'px', top: (top*(item.ICEYP-1)) + 'px' }" style=" position: absolute;">
              <div class="listCenter" :class="setDivClass(item)" @click="openFreezer(item)">
                <p v-text="item.ICENO" class="itemNo">0</p>
                <div class="iceName">
                  {{item.REGNAME}}
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- 登记 -->
    <el-dialog title="冷藏登记" :visible.sync="regVisible">
      <div style="margin:30px 50px">
        <div class="layui-form-item">
          <label class="layui-form-label">存入时间</label>
          <div class="layui-input-inline">
            <el-date-picker v-date v-model="crDataTime" type="datetime" class="longtext" placeholder="选择日期时间"> </el-date-picker>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者类型</label>
            <div class="layui-inline">
              <el-radio-group size="large" v-model="regData.REGBONETYPE">
                <el-radio-button v-for="(item,index) in boneType" :key="index" :label="item.CodeValue" class="radio">
                  <span>{{item.CodeName}}</span>
                </el-radio-button>
              </el-radio-group>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者性别</label>
            <div class="layui-inline">
              <el-radio-group size="large" v-model="regData.REGSEX">
                <el-radio-button v-for="(item,index) in sex" :key="index" :label="item.CodeValue" class="radio">
                  <span>{{item.CodeName}}</span>
                </el-radio-button>
              </el-radio-group>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">死亡原因</label>
            <div class="layui-input-inline">
              <el-cascader :options="cause" v-model="cauinfo" filterable clearable>
              </el-cascader>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">接尸地点</label>
            <div class="layui-input-inline">
              <el-select v-model="regData.REGCYADDRESS" placeholder="请选择常用接尸地址">
                  <el-option :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue" v-for="item in commonAddr"></el-option>
                </el-select>
              <!-- <el-cascader :options="commonAddr" v-model="addinfo" filterable clearable>
              </el-cascader> -->
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">接尸车辆</label>
            <div class="layui-input-inline">
              <el-cascader :options="carLics" v-model="cdhinfo" filterable clearable>
              </el-cascader>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">驾驶员</label>
            <div class="layui-input-inline">
              <el-select v-model="driver" clearable placeholder="请选择">
                <el-option v-for="item in driverList" :key="item.STAID" :label="item.STANAME" :value="item.STAID">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">接尸时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="jsDataTime" class="longtext" type="datetime" placeholder="选择日期时间"> </el-date-picker>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button type="primary" :loading="this.$store.state.isloading" @click="submitReg">
          <i class="layui-icon">&#xe642;</i><span> 登 记</span>
        </el-button>
      </div>
    </el-dialog>
    <!-- 存入 -->
    <el-dialog title="冷藏存入" :visible.sync="depVisible">
      <div style="margin:30px 50px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.deadseachno" placeholder="业务编号" v-focus @keyup.enter.native="SeachDead($event)" clearable></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <div class="layui-input-inline">
              <el-button type="primary" @click="openRegCheck">选取逝者</el-button>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.deadName" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">死亡日期</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.deaddate" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">经办家属</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.linkMan" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.linkTel" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">车号</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.CARLIC" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.CDHLINKMAN" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">接尸地点</label>
          <div class="layui-input-inline">
            <el-input v-model="deaddata.CDHADDRESS" style="width:480px" readonly></el-input>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">存入时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="crDataTime" type="datetime" class="longtext" placeholder="选择日期时间"> </el-date-picker>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button type="primary" :loading="this.$store.state.isloading" @click="submitAdd" :disabled="IsSubmit">
          <i class="layui-icon">&#xe619;</i><span> 存 入</span>
        </el-button>
      </div>
    </el-dialog>
    <!-- 取出 -->
    <el-dialog title="冷藏取出" :visible.sync="takeoutVisible">
      <div style="margin:30px 50px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.deadName" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">存入日期</label>
            <div class="layui-input-inline">
              <el-input v-model="ichdataExtend.saveDates" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">取出日期</label>
            <div class="layui-input-inline">
              <el-date-picker v-model="ichdata.takedate" type="date" placeholder="选择日期">
              </el-date-picker>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">取出时间</label>
            <div class="layui-input-inline">
              <el-time-picker v-model="ichdata.taketime" placeholder="选择时间">
              </el-time-picker>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button type="primary" @click="takeoutIce">
          <i class="layui-icon">&#xe61a;</i><span> 取 出</span>
        </el-button>
      </div>
    </el-dialog>
    <!-- 冰柜 -->
    <el-dialog :visible.sync="freezerVisible" v-if="freezerVisible">
      <div class="freezer" v-if="ice">
        <div class="listCenter">
          <p v-text="ice.ICENO" class="itemNo">0</p>
          <div class="empty" v-if="ice.IceUse.length === 0">
            <!-- <i class="layui-icon" @click="operate(ice,OPEARTCODE.CR)">&#xe61f;</i> -->
          </div>
          <div class="notempty" v-else-if="ice.IceUse.length > 0">
            <el-carousel arrow="always" trigger="click" :autoplay="false" :initial-index="carIndex" @change="getReg($event)" ref="carousel">
              <el-carousel-item v-for="index in ice.IceUse.length" :key="index">
                <div class="iceNo">{{index}}/{{ice.IceUse.length}}</div>
                <div class="iceName" v-loading="iceLoading" element-loading-text="数据获取中">
                  <ul>
                    <li>
                      <label class="ice-label">逝者姓名:</label>
                      <label class="ice-value">{{deaddata.deadName}}</label>
                    </li>
                    <li>
                      <label class="ice-label">死亡日期:</label>
                      <label class="ice-value">{{deaddata.deaddate}}</label>
                    </li>
                    <li>
                      <label class="ice-label">经办家属:</label>
                      <label class="ice-value">{{deaddata.linkMan}}</label>
                    </li>
                    <li>
                      <label class="ice-label">联系电话:</label>
                      <label class="ice-value">{{deaddata.linkTel}}</label>
                    </li>
                    <li>
                      <label class="ice-label">存入时间:</label>
                      <label class="ice-value">{{ichdataExtend.saveDates}}</label>
                    </li>
                    <li>
                      <label class="ice-label">车号:</label>
                      <label class="ice-value">{{deaddata.CARLIC}}</label>
                    </li>
                    <li>
                      <label class="ice-label">联系人:</label>
                      <label class="ice-value">{{deaddata.CDHLINKMAN}}</label>
                    </li>
                    <li>
                      <label class="ice-label">接运地址:</label>
                      <label class="ice-value">{{deaddata.CDHADDRESS}}</label>
                    </li>
                  </ul>
                </div>
              </el-carousel-item>
            </el-carousel>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <div style="zoom:130%;margin:auto;" class="layui-btn-group">
          <button class="layui-btn layui-btn-lg layui-btn-normal" @click="operate(ice,OPEARTCODE.DJ)">
                  <i class="layui-icon">&#xe642;</i>
                  <span>登 记</span>
                </button>
          <button class="layui-btn layui-btn-lg layui-btn-normal" @click="operate(ice,OPEARTCODE.CR)">
                  <i class="layui-icon">&#xe619;</i> 
                  <span>存 入</span>
                </button>
          <button class="layui-btn layui-btn-lg layui-btn-normal" @click="operate(ice,OPEARTCODE.QC)" v-if="ice.IceUse.length > 0">
                  <i class="layui-icon">&#xe61a;</i> 
                  <span>取 出</span>
                </button>
          <button class="layui-btn layui-btn-lg layui-btn-normal" @click="operate(ice,OPEARTCODE.CZ)" v-if="ice.IceUse.length > 0">
                  <i class="layui-icon">&#xe654;</i> 
                  <span>操 作</span>
                </button>
          <button class="layui-btn layui-btn-lg layui-btn-danger" @click="operate(ice,OPEARTCODE.DELETE)" v-if="ice.IceUse.length > 0">
                  <i class="layui-icon">&#xe640;</i> 
                  <span>删 除</span>
                </button>
        </div>
      </div>
    </el-dialog>
    <!-- 操作 -->
    <el-dialog title="冰柜操作" :visible.sync="operVisible">
      <div style="margin:30px 50px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.deadName" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">存入日期</label>
            <div class="layui-input-inline">
              <el-input v-model="ichdataExtend.saveDates" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">选择操作</label>
          <div class="layui-inline">
            <el-radio-group size="large" v-model="operCode">
              <el-radio-button v-for="(item,index) in operCodelist" :key="index" :label="item.CodeValue" class="radio">
                <span style="display:block;">{{item.CodeName}}</span>
              </el-radio-button>
            </el-radio-group>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button type="primary" @click="opreation">
          <i class="layui-icon">&#xe654;</i><span> 操 作</span>
        </el-button>
      </div>
    </el-dialog>
    <!-- 逝者选择 -->
    <el-dialog title="逝者选择" :visible.sync="regCheckVisible">
      <div class="layui-form-item">
        <label class="layui-form-label">到馆时间</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="regCheckDate" @change="getRegData" type="date" placeholder="选择日期时间"> </el-date-picker>
        </div>
      </div>
      <div style="height:400px;max-height:400px;overflow:auto;">
        <table class="layui-table">
          <thead>
            <tr>
              <th>业务编号</th>
              <th>逝者姓名</th>
              <th>联系人</th>
              <th>死亡日期</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in regCheckList">
              <td>{{item.REGBUSNUM}}</td>
              <td>{{item.REGNAME}}</td>
              <td>{{item.REGHANDLERNAME}}</td>
              <td>{{item.REGDEATHDATE}}</td>
              <td><button @click="getDead(item)" class="layui-btn layui-btn-normal">选择</button></td>
            </tr>
          </tbody>
        </table>
      </div>
    </el-dialog>
  </div>
</template>
<style lang="less" scoped>
  .refresh {
    margin-left: 40px;
    margin-top: -6px;
  }
  .longtext {
    width: 480px;
  }
  .btnCenter {
    text-align: center;
  }
  table.tableIfon {
    th {
      font-weight: normal;
    }
    td {
      text-align: left;
      padding-right: 20px;
    }
  }
  select::-ms-expand {
    //ie下啦箭头隐藏
    display: none;
  }
  select.nameOptions {
    width: 100px;
    display: inline-block;
    margin-right: 10px;
    background: transparent;
    border: none;
    box-shadow: inset 0 0px 0px rgb(255, 255, 255);
    margin: auto;
    display: block;
    text-align-last: center;
  }
  .datepicker-popup {
    position: fixed !important;
  }
  table.iceTable {
    width: 100%;
    td {
      width: 50px;
      height: 200px;
      border: 1px solid #dcdcdc;
    }
  }
  div.tableContainer {
    width: 100%;
    max-height: 680px;
    overflow: auto;
    margin-top: 20px;
    ul.tableIceArea {
      width: 100%;
      height: 100%;
      li {
        width: 200px;
        height: 180px;
        div.listCenter {
          p.itemNo {
            text-align: center;
            padding-top: 15px;
            font-size: 18px;
            color: white;
            font-weight: bold;
          }
          div.iceName {
            height: 40px;
            width: 100%;
            text-align: center;
            padding-top: 15px;
            font-size: 18px;
            color: white;
            font-weight: bold;
          }
        }
      }
    }
  }
  .linkdisable {
    background: #eef1f6;
    color: #878d99;
    cursor: not-allowed;
  }
  .iceplace {
    margin: 5px;
    width: 200px;
    height: 180px;
    float: left;
  }
  .iceplacedefault {
    background-color: #878d99;
  }
  .iceplaceCanuse {
    background-color: #67c23a;
  }
  .iceplaceUseed {
    background-color: #eb9e05;
  }
  .iceplaceMoreUseed {
    background-color: #fa5555;
  }
  div.freezer {
    text-align: center;
    div.listCenter {
      margin: auto;
      width: 100%;
      height: 400px;
      position: relative;
      .empty {
        text-align: center;
        color: #409eff;
        line-height: 400px;
        i {
          font-size: 150px;
        }
        i:active {
          color: #909399;
        }
      }
      p.itemNo {
        text-align: center;
        padding-top: 10px;
        font-size: 50px;
        color: #409eff;
        font-weight: bold;
      }
      div.iceNo {
        text-align: center;
        font-size: 20px;
        font-weight: bold;
      }
      div.iceName {
        height: 200px;
        width: 100%;
        text-align: center;
        padding-top: 15px;
        font-size: 18px;
        font-weight: bold;
        .ice-label {
          text-align: right;
          width: 100px;
        }
        .ice-value {
          text-align: left;
          margin-left: 10px;
          min-width: 100px;
        }
      }
      div.tableToolList {
        overflow: hidden;
        ul.tableTool {
          width: 90px;
          margin: 10px auto 0;
          overflow: hidden;
          height: 30px;
          li {
            float: left;
            width: 30px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            padding: 0;
            margin: 0;
            cursor: pointer;
            position: inherit;
          }
          li.saveBtn {
            background: #009289;
            color: white;
          }
          li.takeBtn {
            // background: #eaeaea;
            background: #ff2021;
            color: white;
          }
          li.takeBtnEnadble {
            // background: #eaeaea;
            background: #eef1f6;
            color: #878d99;
            cursor: not-allowed;
          }
          li.moreBtn {
            background: #ef9000;
            color: white;
            span.el-dropdown-link {
              color: white;
            }
          }
        }
      }
    }
  }
</style>
<script>
  import apiBase from "@/api/apiBase.js";
  import calendar from "@/components/sweetModal/calendar.vue";
  import {
    formatDate,
    timeStringToDate
  } from "@/utils/date.js";
  import sweetModal from "@/components/sweetModal";
  export default {
    name: "iceUse",
    data() {
      return {
        OPEARTCODE: {
          DJ: "登记",
          CR: "存入",
          QC: "取出",
          MODIFY: "修改",
          DELETE: "删除",
          INFO: "详情",
          CZ: "操作"
        },
        isMore: false,
        takeoutVisible: false,
        freezerVisible: false,
        regVisible: false,
        depVisible: false,
        operVisible: false,
        regCheckVisible: false,
        title: null,
        IsSubmit: true,
        IsEnter: false,
        left: "210",
        top: "190",
        ice: null,
        iceLoading: false,
        seachdataExtent: {
          Regdate: null
        },
        icaSelectIndex: 0,
        iceAreaItem: {
          ICAID: null
        },
        iceArea: [], //获取冰柜区域下拉框
        iceAreaInfo: [], //获取冰柜区域的冰柜及使用信息
        deaddata: {
          deadseachno: null,
          deadselectno: null,
          deadid: null,
          deadName: null,
          deaddate: null,
          linkMan: null,
          linkTel: null,
          deadRemark: null,
          CARLIC: null,
          CDHADDRESS: null,
          CDHLINKMAN: null
        },
        icedata: {
          iceid: null,
          icename: null,
          iceuse: []
        },
        ichdata: {
          ichid: null,
          iceid: null,
          savedate: null,
          savetime: null,
          takedate: null,
          taketime: null
        },
        ichdataExtend: {
          ichEndDates: null,
          saveDates: null
        },
        IceUse: [], //取出  业务编号
        commonAddr: [],
        boneType: [],
        sex: [],
        cause: [],
        carLics: [],
        addList: [],
        operCodelist: [],
        regData: {},
        driver: null,
        driverList: [],
        cauinfo: null,
        addinfo: null,
        cdhinfo: null,
        crDataTime: null,
        jsDataTime: null,
        operCode: null,
        carIndex: 0,
        regCheckDate: null,
        regCheckList: []
      };
    },
    methods: {
      toggle() {
        this.isMore = !this.isMore;
      },
      getReg(item) {
        console.log(item);
        this.carIndex = item;
        if (this.ice.IceUse && this.ice.IceUse.length > 0) {
          this.icedata.iceid = this.ice.ICEID;
          this.deaddata.deadselectno = this.ice.IceUse[item].REGBUSNUM;
          this.GetIchInfo();
        }
      },
      //打开冰柜
      openFreezer(ice) {
        this.ice = ice;
        //this.getReg(0);
        //this.$refs.freezer.open();
        this.$nextTick(function() {
          this.carIndex = 0;
          this.freezerVisible = true;
        });
        this.isMore = false;
      },
      //功能操作
      operate(ice, order) {
        this.ice = ice;
        this.icedata.iceid = ice.ICEID;
        this.order = order;
        this.title = this.order;
        switch (this.order) {
          case this.OPEARTCODE.DJ:
            this.DeaddataRepeat();
            this.crDataTime = new Date();
            this.getBoneType();
            this.getSex();
            this.getCausa();
            this.getCar();
            this.getAddressMap();
            this.getDriver();
            this.getCommonAddr();
            this.regVisible = true;
            break;
          case this.OPEARTCODE.CR:
            this.DeaddataRepeat();
            this.crDataTime = new Date();
            this.depVisible = true;
            break;
          case this.OPEARTCODE.QC:
            this.ichdata.takedate = new Date();
            this.ichdata.taketime = new Date();
            this.takeoutVisible = true;
            break;
          case this.OPEARTCODE.CZ:
            this.operCode = null;
            this.getOperatingCode();
            this.operVisible = true;
            //this.opreation();
            break;
          case this.OPEARTCODE.DELETE:
            this.deleteIce();
            break;
          default:
        }
        this.isMore = false;
      },
      //重置数据
      DeaddataRepeat() {
        this.driver = null;
        this.jsDataTime = null;
        this.cauinfo = [];
        this.addinfo = [];
        this.cdhinfo = [];
        Object.assign(this.$data.deaddata, this.$options.data().deaddata);
        Object.assign(this.$data.regData, this.$options.data().regData);
      },
      //删除冰柜使用
      deleteIce() {
        this.$confirm("确认是否删除?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
            let data = {
              ICHID: this.ichdata.ichid
            };
            this.$store.state.isloading = true;
            apiBase.DoService(data, apiBase.getApiAdress().IceUse.Delete, res => {
              this.$store.state.isloading = false;
              this.getIceData();
              this.$message.success("删除成功");
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
      },
      //取出
      takeoutIce() {
        this.$confirm("确认是否取出?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
            var takedate = formatDate(this.ichdata.takedate, "yyyyMMdd");
            var taketime = formatDate(this.ichdata.taketime, "hhmmss");
            let data = {
              ICHICEID: this.icedata.iceid,
              ICHREGID: this.deaddata.deadid,
              ICHENDDATE: takedate,
              ICHENDTIME: taketime
            };
            this.$store.state.isloading = true;
            apiBase.DoService(data, apiBase.getApiAdress().IceUse.EndUse, res => {
              this.$store.state.isloading = false;
              this.takeoutVisible = false;
              this.getIceData();
              this.$message.success("取出成功");
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
      },
      GetIchInfo() {
        let data = {
          ICHICEID: this.icedata.iceid,
          ICHREGBUSNUM: this.deaddata.deadselectno
        };
        this.iceLoading = true;
        apiBase.DoService(
          data,
          apiBase.getApiAdress().IceUse.GetRegistrationAndUseByNo,
          res => {
            if(res.data.content.CDH){
              this.deaddata.CARLIC = res.data.content.CDH.CARLIC;
              this.deaddata.CDHADDRESS = res.data.content.CDH.CDHADDRESS;
              this.deaddata.CDHLINKMAN = res.data.content.CDH.CDHLINKMAN;
            }
            if (res.data.content.REG) {
              this.deaddata.deadid = res.data.content.REG.REGID;
              this.deaddata.deadName = res.data.content.REG.REGNAME;
              this.deaddata.deaddate = res.data.content.REG.REGDEATHDATE;
              this.deaddata.linkMan = res.data.content.REG.REGHANDLERNAME;
              this.deaddata.linkTel = res.data.content.REG.REGHANDLERLINK;
            }
            if (res.data.content.ICH) {
              this.ichdata.takedate = res.data.content.ICH.ICHENDDATE;
              this.ichdata.taketime = res.data.content.ICH.ICHENDTIME;
              this.ichdata.savedate = res.data.content.ICH.ICHBEGDATE;
              this.ichdata.savetime = res.data.content.ICH.ICHBEGTIME;
              this.ichdata.ichid = res.data.content.ICH.ICHID;
              this.ichdataExtend.saveDates =  this.ichdata.savedate;
              // this.ichdataExtend.saveDates = timeStringToDate(
              //   this.ichdata.savetime,
              //   this.ichdata.savedate
              // );
              // console.log('ichdataExtend',this.ichdataExtend.saveDates)
              // this.ichdataExtend.saveDates = formatDate(
              //   this.ichdataExtend.saveDates,
              //   "yyyy-MM-dd"
              // );
            }
           
            this.iceLoading = false;
          },
          res => {
            this.$message.error(res.data.msg);
            this.iceLoading = false;
          }
        );
      },
      //根据iceID获取ice
      getIce(id) {
        for (let ice of this.iceAreaInfo) {
          if (ice.ICEID === id) {
            this.ice = ice;
            if (this.ice.IceUse) {
              if (
                this.order === this.OPEARTCODE.DJ ||
                this.order === this.OPEARTCODE.CR
              ) {
                this.carIndex = this.ice.IceUse.length - 1;
              } else if (this.order === this.OPEARTCODE.QC) {
                if (this.carIndex > 0) {
                  this.carIndex = this.carIndex - 1;
                } else {
                  this.carIndex = 0;
                }
              }
            }
            this.$nextTick(function() {
              this.$refs.carousel.setActiveItem(this.carIndex);
            });
            return;
          }
        }
      },
      //存入
      submitAdd() {
        let data = {
          ICHICEID: this.icedata.iceid,
          ICHREGBUSNUM: this.deaddata.deadseachno,
          ICHBEGDATE: formatDate(this.crDataTime, "yyyyMMdd"),
          ICHBEGTIME: formatDate(this.crDataTime, "hhmmss")
        };
        this.$store.state.isloading = true;
        apiBase.DoService(data, apiBase.getApiAdress().IceUse.StartUse, res => {
          this.$store.state.isloading = false;
          this.getIceData();
          this.$message.success("存入成功");
          this.depVisible = false;
        });
      },
      //登记
      submitReg() {
        this.regData.REGCAUSA = this.cauinfo[0];
        this.regData.REGCAUSASON = this.cauinfo[1];
       // this.regData.REGADDID = this.addinfo[this.addinfo.length - 1];
        this.regData.REGDATE = formatDate(this.jsDataTime, "yyyyMMdd");
        this.regData.REGTIME = formatDate(this.jsDataTime, "hhmmss");
        let data = JSON.parse(JSON.stringify(this.regData));
        console.log('regData',data)
        data.Ich = {
          ICHICEID: this.icedata.iceid,
          ICHBEGDATE: formatDate(this.crDataTime, "yyyyMMdd"),
          ICHBEGTIME: formatDate(this.crDataTime, "hhmmss")
        };
        data.Cdh = {
          CDHCARID: this.cdhinfo[1],
          CDHDRIVER: this.driver
        };
        this.$store.state.isloading = true;
        apiBase.DoService(
          data,
          apiBase.getApiAdress().IceUse.Registation,
          res => {
            this.$store.state.isloading = false;
            this.getIceData();
            this.$message.success("登记成功");
            //this.$refs.dialog1.close();
            this.regVisible = false;
          }
        );
      },
      //冷藏操作
      opreation() {
        this.$confirm("确认是否操作?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
            let data = {
              OFFCODNAME: this.operCode,
              OFFREGID: this.deaddata.deadid
            };
            apiBase.DoService(
              data,
              apiBase.getApiAdress().IceUse.Opreation,
              res => {
                this.iceArea = res.data.content;
                this.$message.success("操作成功");
                this.operVisible = false;
              }
            );
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
      },
      //获取冰柜区域
      getIceArea() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().IceUse.QueryIceArea,
          res => {
            this.iceArea = res.data.content;
            if (!this.iceArea && this.iceArea.length === 0)
              this.icaSelectIndex = null;
            this.getIceData();
          }
        );
      },
      //打开逝者选取
      openRegCheck() {
        this.regCheckDate = new Date();
        this.getRegData();
        this.regCheckVisible = true;
      },
      //获取冰柜区域的冰柜及使用信息
      getIceData() {
        if (
          this.icaSelectIndex === null ||
          this.iceArea === undefined ||
          this.iceArea.length === 0
        )
          return;
        this.iceAreaItem = this.iceArea[this.icaSelectIndex];
        console.log("iceAreaItem", this.icaSelectIndex);
        let data = {
          //请求体
          ICAID: this.iceAreaItem.ICAID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().IceUse.QueryIceUseByArea,
          res => {
            this.iceAreaInfo = res.data.content;
            this.iceAreaInfo.forEach((item, index) => {
              if (item.IceUse !== undefined && item.IceUse.length > 0)
                item.REGNAME = item.IceUse[0].REGNAME;
              else item.REGNAME = "";
            });
            if (this.ice) {
              this.getIce(this.ice.ICEID);
            }
          }
        );
      },
      //扫码获取逝者
      SeachDead(ev) {
        if (ev.keyCode === 13) {
          this.IsEnter = true;
          let data = {
            ICHICEID: this.icedata.iceid,
            ICHREGBUSNUM: this.deaddata.deadseachno
          };
          apiBase.DoService(
            data,
            apiBase.getApiAdress().IceUse.GetRegistrationAndUseByNo,
            res => {
              if(res.data.content.CDH){
                this.deaddata.CARLIC = res.data.content.CDH.CARLIC;
                this.deaddata.CDHADDRESS = res.data.content.CDH.CDHADDRESS;
                this.deaddata.CDHLINKMAN = res.data.content.CDH.CDHLINKMAN;
              }
              if (res.data.content.REG) {
                this.deaddata.deadid = res.data.content.REG.REGID;
                this.deaddata.deadName = res.data.content.REG.REGNAME;
                this.deaddata.deaddate = res.data.content.REG.REGDEATHDATE;
                this.deaddata.linkMan = res.data.content.REG.REGHANDLERNAME;
                this.deaddata.linkTel = res.data.content.REG.REGHANDLERLINK;
              }

              if (this.deaddata.deadid) {
                this.IsSubmit = false;
              } else {
                this.IsSubmit = true;
                this.$message.warning("未找到相关信息");
              }
            }
          );
        } else {
          if (this.IsEnter === true) {
            this.deaddata.deadseachno = "";
            this.IsEnter = false;
          }
        }
      },
      getDead(item) {
        this.deaddata.deadseachno = item.REGBUSNUM;
        this.deaddata.deadid = item.REGID;
        this.deaddata.deadName = item.REGNAME;
        this.deaddata.deaddate = item.REGDEATHDATE;
        this.deaddata.linkMan = item.REGHANDLERNAME;
        this.deaddata.linkTel = item.REGHANDLERLINK;
        this.deaddata.CARLIC = item.Cdh.CARLIC;
        this.deaddata.CDHADDRESS = item.Cdh.CDHADDRESS;
        this.deaddata.CDHLINKMAN = item.Cdh.CDHLINKMAN;
        this.regCheckVisible = false;
        this.IsSubmit = false;
      },
      //刷新
      btnOnload() {
        this.getIceData();
      },
      setDivClass(ice) {
        if (!ice) return "";
        if (!ice.IceUse || ice.IceUse.length === 0)
          return "iceplace iceplaceCanuse";
        else if (ice.IceUse.length === 1) return "iceplace iceplaceUseed";
        else if (ice.IceUse.length > 1) return "iceplace iceplaceMoreUseed";
      },
      getBoneType() {
        let data = {};
        apiBase.DoService(data, apiBase.getApiAdress().Code.GetBoneType, res => {
          this.boneType = res.data.content;
        });
      },
      getSex() {
        let data = {};
        apiBase.DoService(data, apiBase.getApiAdress().Code.GetSex, res => {
          this.sex = res.data.content;
        });
      },
      getDriver() {
        let data = {};
        apiBase.DoService(data, apiBase.getApiAdress().Staff.QueryDriver, res => {
          this.driverList = res.data.content;
        });
      },
      //获取死亡原因
      getCausa() {
        let data = {};
        apiBase.DoService(data, apiBase.getApiAdress().Code.GetCausa, res => {
          let caudata = res.data.content;
          this.cause = caudata.map(item => ({
            label: item.CAENAME,
            value: item.CAEID,
            children: item.Caus.map(itemCau => ({
              label: itemCau.CAUNAME,
              value: itemCau.CAUID
            }))
          }));
        });
      },
      //获取车辆信息
      getCar() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Car.QueryCarByType,
          res => {
            let cardata = res.data.content;
            let legendsCarData = cardata.map(item => ({
              label: item.CodeName,
              value: item.CodeValue,
              children: item.list_Cars.map(caritem => ({
                label: caritem.CARLIC,
                value: caritem.CARID
              }))
            }));
            this.carLics = legendsCarData;
            this.carLics.push({
              label: "自送",
              value: null,
              children: [{
                label: "自送",
                value: null
              }]
            });
          }
        );
      },
      //获取常用地址
      getCommonAddr() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Code.GetCommonAddress,
          res => {
            this.commonAddr = res.data.content;
          }
        );
      },
      //获取地址
      getAddressMap() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Code.GetAddressMap,
          res => {
            let addData = res.data.content;
            let legendsAddData = addData.map(first => ({
              label: first.ADDNAME,
              value: first.ADDID,
              children: first.Children.map(second => ({
                label: second.ADDNAME,
                value: second.ADDID
              }))
            }));
            this.addList = legendsAddData;
          }
        );
      },
      //获取操作码
      getOperatingCode() {
        let data = {
          Data: {}
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Code.GetOperatingCode,
          res => {
            this.operCodelist = res.data.content;
          }
        );
      },
      //获取火化登记数据
      getRegData() {
        let data = {
          Data: {
            RegdateEquals: formatDate(this.regCheckDate, "yyyyMMdd")
          }
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Registration.QueryRegistration,
          res => {
            this.regCheckList = res.data.content.OutData;
          }
        );
      }
    },
    mounted() {
      this.getIceArea();
      this.getIceData();
    },
    created() {},
    watch: {
      "ichdataExtend.saveDates": function(val) {
        if (val) {
          this.ichdata.savedate = formatDate(val, "yyyyMMdd");
          this.ichdata.savetime = formatDate(val, "hhmmss");
        }
      },
      "ichdataExtend.ichEndDates": function(val) {
        if (val) {
          this.ichdata.takedate = formatDate(val, "yyyyMMdd");
          this.ichdata.taketime = formatDate(val, "hhmmss");
        }
      }
    },
    components: {
      sweetModal,
      calendar
    },
    directives: {
      focus: {
        update: function(el) {
          el.children[0].focus();
        }
      }
    }
  };
</script>
